package com.zuihai.app.mvp.ui.activity.base;

import android.support.annotation.DrawableRes;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.mvp.IPresenter;


import com.zuihai.app.R;
import com.zuihai.app.mvp.model.entity.InitUser;
import com.zuihai.app.mvp.ui.widget.ToolbarWrapper;

import org.litepal.crud.DataSupport;

import butterknife.BindView;

/**
 * 白底 足迹收藏 我发布的 我的消息
 * Created by Administrator on 2017/5/10 0010.
 */

public abstract class ToolBarBaseNewActivity<P extends IPresenter> extends BaseActivity<P> {
    @BindView(R.id.toolbar)
    ToolbarWrapper toolbar;

    @BindView(R.id.btn_top_back)
    ImageView ivBack;

    @BindView(R.id.fl_title)
    FrameLayout frameLayout;

    @BindView(R.id.tv_tobar_title_text)
    TextView tvTitle;

    @BindView(R.id.back_layout)
    FrameLayout backLayout;

    @BindView(R.id.iv_zhanwei)
    ImageView logoView;

    @BindView(R.id.btn_action_one)
    Button actionOne;

    @BindView(R.id.btn_action_two)
    Button actionTwo;

    @BindView(R.id.btn_action_three)
    Button actionThree;

    @BindView(R.id.btn_action_add_one)
    Button actionFour;

    private InitUser initUser;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    @Override
    protected View initView() {
        //获取ToolbarLayout
        ViewGroup toolbarLayout = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.activity_top_bar_base, null, false);
        //找到内容容器
        ViewGroup contentContainer = (ViewGroup) toolbarLayout.findViewById(R.id.fl_title);
        //将内容放入到容器中
        LayoutInflater.from(this).inflate(initContentView(), contentContainer, true);

        return toolbarLayout;
    }

    protected abstract int initContentView();

    @Override
    protected void initBaseToolBar() {
        initBaseToolbar();
    }
    /**
     * 初始化Toolbar布局
     */
    private void initBaseToolbar() {
        setSupportActionBar(toolbar);
        backLayout.setVisibility(hasBack() ? View.VISIBLE: View.GONE);
        backLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    public boolean hasBack() {
        return true;
    }
    protected void setTitle(String title) {
        if (!TextUtils.isEmpty(title)) {
            tvTitle.setText(title);
        }
    }
    public void setupActionThree(@DrawableRes int drawable, View.OnClickListener listener) {
        actionThree.setVisibility(View.VISIBLE);
        actionThree.setBackgroundResource(drawable);
        actionThree.setOnClickListener(listener);
    }

    public ImageView getIvBack() {
        return ivBack;
    }

    public ToolbarWrapper getToolbar() {
        return toolbar;
    }

    public TextView getTvTitle() {
        return tvTitle;
    }

    public Button getActionOne() {
        return actionOne;
    }

    public ImageView getLogoView() {
        return logoView;
    }

    public FrameLayout getFrameLayout(){
        return backLayout;
    }

    public Button getActionTwo() {
        return actionTwo;
    }

    public Button getActionThree() {
        return actionThree;
    }

    public Button getActionFour(){
        return actionFour;
    }

    public InitUser getInitUser(){
        return  initUser = DataSupport.findFirst(InitUser.class);
    }

}
